const ACCESS_KEY = "alexmaodali";
const BASE_URL = "https://tea.qingnian8.com/api/bizhi";
export const request = (config = {}) => {
  let { url, method = "GET", header = {}, data = {} } = config;

  url = BASE_URL + url;
  header["access-key"] = ACCESS_KEY;

  return new Promise((resolve, reject) => {
    uni.request({
      url,
      data,
      method,
      header,
      success: (res) => {
        if (res.data.errCode == 0 || res.data.code == 200) {
          resolve(res.data);
        } else if (res.data.errCode == 400) {
          uni.showModal({
            title: "请求错误",
            content: res.data.errMsg,
          });
          reject(res.data.errMsg);
        } else {
          uni.showToast({
            title: res.data.errMsg,
            icon: "none",
          });
          reject(res.data.errMsg);
        }
      },
    });
  });
};
